{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "49aacd51-1fa9-42a5-8435-c05fcb4d1b2a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 2 3]\n",
      " [4 5 6]\n",
      " [7 8 9]]\n",
      "[10 10 10]\n",
      "[[11 12 13]\n",
      " [14 15 16]\n",
      " [17 18 19]]\n",
      "[[11 12 13]\n",
      " [14 15 16]\n",
      " [17 18 19]]\n",
      "减 [[-9 -8 -7]\n",
      " [-6 -5 -4]\n",
      " [-3 -2 -1]]\n",
      "乘 [[10 20 30]\n",
      " [40 50 60]\n",
      " [70 80 90]]\n",
      "除 [[0.1 0.2 0.3]\n",
      " [0.4 0.5 0.6]\n",
      " [0.7 0.8 0.9]]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "n1=np.array([[1,2,3],[4,5,6],[7,8,9]])\n",
    "n2=np.array([10,10,10])\n",
    "print(n1)\n",
    "print(n2)\n",
    "# 数组的加减乘除\n",
    "print(np.add(n1,n2))\n",
    "print(n1+n2)\n",
    "print('减', np.subtract(n1,n2))\n",
    "print('乘', np.multiply(n1, n2))\n",
    "print('除', np.divide(n1, n2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "bbf74646-0bd0-4df1-b16f-edaa012f6d28",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[4.         0.57142857 0.5        0.01      ]\n"
     ]
    }
   ],
   "source": [
    "# 倒数\n",
    "n1=np.array([0.25, 1.75, 2, 100])\n",
    "print(np.reciprocal(n1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "f8745011-2970-4c40-afb8-f04853034e9b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[        10      10000 1000000000]\n"
     ]
    }
   ],
   "source": [
    "# 幂运算\n",
    "n1=np.array([10, 100, 1000])  # n1这个数组的n2次幂\n",
    "n2=np.array([1, 2, 3])\n",
    "print(np.power(n1, n2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "fab24f84-5a05-49f9-bb3a-bdeec5f3a143",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 2  0 -2]\n"
     ]
    }
   ],
   "source": [
    "# 求余\n",
    "n1=np.array([10, 20, 30])\n",
    "n2=np.array([4, 5, -8])\n",
    "print(np.mod(n1, n2))\n",
    "# 30除3以-8的余数的公式 余=a-n*[a//n]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "e9849b2e-156c-4c5f-9740-5d249f371b03",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 1.55      6.823     0.11589   3.141545 -3.456   ]\n",
      "[ 2.  7.  0.  3. -3.]\n",
      "[ 1.55  6.82  0.12  3.14 -3.46]\n"
     ]
    }
   ],
   "source": [
    "# 四舍五入\n",
    "n=np.array([1.55, 6.823, 0.11589, 3.141545, -3.456])\n",
    "print(n)\n",
    "print(np.around(n))\n",
    "print(np.round(n, decimals=2))  # 保留小数点后2位"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "9dbbc163-48de-413e-8b15-69812044e673",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 2.  7.  1.  4. -3.]\n",
      "[ 1.  6.  0.  3. -4.]\n"
     ]
    }
   ],
   "source": [
    "# 向上取整与向下取整\n",
    "print(np.ceil(n))\n",
    "print(np.floor(n))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "3e31381f-1fa0-4ba7-b746-f3f1ad25d12f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0.         0.5        0.70710678 0.8660254  1.        ]\n",
      "[1.00000000e+00 8.66025404e-01 7.07106781e-01 5.00000000e-01\n",
      " 6.12323400e-17]\n",
      "[0.00000000e+00 5.77350269e-01 1.00000000e+00 1.73205081e+00\n",
      " 1.63312394e+16]\n"
     ]
    }
   ],
   "source": [
    "# 三角函数\n",
    "n=np.array([0, 30, 45, 60, 90])\n",
    "print(np.sin(n*np.pi/180))\n",
    "print(np.cos(n*np.pi/180))\n",
    "print(np.tan(n*np.pi/180))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ee34d369-b549-45ad-a0ed-f1385f5d7d27",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
